package com.zhanglu.authentication.router;

import com.zhanglu.authentication.service.PermissionService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description
 * @Auther zhanglu
 * @Date 2017/12/13 下午1:49
 */
@RestController
@Slf4j
public class PermissionRouter {
    @Autowired
    private PermissionService permissionService;

    @ApiOperation(value = "判断权限表是否包含角色", notes = "主要用于判定传递到角色中是否拥有权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "serverName", value = "服务名称", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "url", value = "请求路径", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "methodType", value = "请求类型", required = true, dataType = "String", paramType = "query")})
    @ApiResponses({ @ApiResponse(code = 200, message = "请求成功", response = List.class) })
    @GetMapping("/permission/role")
    public List<String> hasPermission(@RequestParam("serverName") String serverName, @RequestParam("url") String url, @RequestParam("methodType") String methodType) {
        return permissionService.getRoleByServerNameAndUrlAndMethodType(serverName, url, methodType);
    }
}
